<?php echo $this->Html->css(array('hProducts', 'date', 'datepicker', 'normalize')) ?>
<?php echo $this->Html->script('date'); ?>

<div class="hProducts index">

  <section class="search dateForm">

    <h2><?php echo __('Historico de Stock - Resumen Gastos Registrados'); ?></h2>


    <?php echo $this->Form->create('HProducts', array('action' => 'index')); ?>
    <label for="from">Fecha Desde</label>
    <input type="text" id="from" name="from" value="<?php echo isset($from) ? $from : '' ?>"/>
    <label for="to">Hasta</label>
    <input type="text" id="to" name="to" value="<?php echo isset($to) ? $to : '' ?>" />
    <?php echo $this->Form->end(array('label' => '', 'class' => 'buttonLupa2', 'div' => false, 'id' => 'searchDate')) ?>
    <?php echo $this->Html->Link('Exportar', array('action' => 'export', isset($from) ? $from : '', isset($to) ? $to : ''), array('id' => 'export')); ?>

  </section>
  <hr>
  <table cellpadding="0" cellspacing="0">
    <tr class="titleTable">
      <th><?php echo $this->Paginator->sort('Punto de Venta'); ?></th>
      <th><?php echo $this->Paginator->sort('Producto'); ?></th>
      <th><?php echo $this->Paginator->sort('fecha'); ?></th>
      <th><?php echo $this->Paginator->sort('Precio de Compra ($)'); ?></th>
      <th><?php echo $this->Paginator->sort('Cantidad'); ?></th>
      <th><?php echo $this->Paginator->sort('Gasto por Producto ($)'); ?></th>
      <th class="actions"><?php echo __('Opciones'); ?></th>
    </tr>

    <?php $totalSuma = 0; ?>
    <?php foreach ($hProducts as $hProduct): ?>
      <tr>
        <td>
          <?php echo $this->Html->link($hProduct['Shop']['name'], array('controller' => 'shops', 'action' => 'view', $hProduct['Shop']['id'])); ?>
        </td>
        <td>
          <?php echo $this->Html->link($hProduct['Product']['name'], array('controller' => 'products', 'action' => 'view', $hProduct['Product']['id'])); ?>
        </td>
        <td><?php echo $this->Time->format('d/m/Y H:i:s', $hProduct['HProduct']['date']) ?>&nbsp;</td>
        
        <td><?php echo h($hProduct['HProduct']['purchase_price']); ?>&nbsp;</td>
        <td><?php echo h($hProduct['HProduct']['quantity']); ?>&nbsp;</td>

        <td><?php
        $totalParcial = ($hProduct['HProduct']['quantity'] * $hProduct['HProduct']['purchase_price'] );

        $totalSuma += $totalParcial;

        echo $totalParcial;
          ?>&nbsp;

        </td>
        <td class="actions">
          <?php // echo $this->Html->link(__('Editar'), array('action' => 'edit', $hProduct['HProduct']['id'], $hProduct['HProduct']['quantity'])); ?>
          <?php echo $this->Form->postLink(__('borrar'), array('action' => 'delete', $hProduct['HProduct']['id'], $hProduct['HProduct']['shop_id'], $hProduct['HProduct']['product_id'], $hProduct['HProduct']['quantity']), null, __('¿Realmente desea eliminar?', $hProduct['HProduct']['id'])); ?>
        </td>



      </tr>
    <?php endforeach; ?>
    <tfoot>
      <tr >
        <th></th>
        <th></th>
        <th></th>
        <th></th>
        <th>Total :</th>
        <th class="total">  <?php echo $totalSuma ?></th>  
        <th></th>


      </tr>
    </tfoot>
  </table>
  <?php echo $this->element('footer/paginator') ?>

</div>
<!--Show General Menu-->
<?php echo $this->element('menues/general') ?>
